using System;
using System.Collections.Generic;
using UnityEngine;

public class PlayerCareerStages : ScriptableObjectSingleton<PlayerCareerStages>
{
	[Serializable]
	public class PlayerCareerStageId
	{
		public enum ListType
		{
			NormalStages = 0,
			OptionalStages = 1
		}

		public ListType listType;

		public int index;

		public PlayerCareerStageDefinition.StageDefinition stage
		{
			get
			{
				PlayerCareerStages instance = ScriptableObjectSingleton<PlayerCareerStages>.instance;
				List<PlayerCareerStageDefinition.StageDefinition> list = ((listType != 0) ? instance.optionalStages : instance.stages);
				return list[Mathf.Clamp(index, 0, list.Count - 1)];
			}
		}

		public PlayerCareerStageId Clone()
		{
			PlayerCareerStageId playerCareerStageId = new PlayerCareerStageId();
			playerCareerStageId.listType = listType;
			playerCareerStageId.index = index;
			return playerCareerStageId;
		}
	}

	[Serializable]
	public class StageGroupId
	{
		public int index = -1;

		public PlayerCareerStageDefinition.StageGroupDefinition group
		{
			get
			{
				if (index < 0)
				{
					return null;
				}
				PlayerCareerStages instance = ScriptableObjectSingleton<PlayerCareerStages>.instance;
				List<PlayerCareerStageDefinition.StageGroupDefinition> stageGroups = instance.stageGroups;
				return stageGroups[Mathf.Clamp(index, 0, stageGroups.Count - 1)];
			}
		}

		public StageGroupId Clone()
		{
			StageGroupId stageGroupId = new StageGroupId();
			stageGroupId.index = index;
			return stageGroupId;
		}
	}

	public List<PlayerCareerStageDefinition.StageDefinition> stages = new List<PlayerCareerStageDefinition.StageDefinition>();

	public List<PlayerCareerStageDefinition.StageDefinition> optionalStages = new List<PlayerCareerStageDefinition.StageDefinition>();

	public List<PlayerCareerStageDefinition.StageGroupDefinition> stageGroups = new List<PlayerCareerStageDefinition.StageGroupDefinition>();

	protected override void Init()
	{
		base.Init();
		int num = 0;
		foreach (PlayerCareerStageDefinition.StageDefinition stage in stages)
		{
			stage.Init(num);
			num++;
		}
		num = 0;
		foreach (PlayerCareerStageDefinition.StageDefinition optionalStage in optionalStages)
		{
			optionalStage.Init(num);
			optionalStage.isOptional = true;
			num++;
		}
	}

	public PlayerCareerStageDefinition.StageDefinition CurrentStage()
	{
		return stages[Mathf.Min(SingletonInit<PlayerCareer>.Instance.maxStageReached, stages.Count - 1)];
	}
}
